package com;

import static org.junit.Assert.*;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.mybatis.User;
import com.mybatis.UserDao;
import com.mybatis.Util;

import java.util.HashMap;

public class testUserDao {
	SqlSession session = null;

	@Before
	public void getSession() {
		session = Util.getSession().openSession();
	}

	@Test
	public void TestUtil() {
        HashMap<String, Object> param = new HashMap<>();
        param.put("userId", "5");
        User u = session.selectOne("com.mybatis.UserDao.selectUserByID", param);
		System.out.println(u.getUserAddress());
	}

	@Test
	public void testSelect() {
		UserDao userdao = session.getMapper(UserDao.class);
		User u = userdao.selectUserByID(5);
		System.out.println(u.getUserAddress());
		Logger log=Logger.getRootLogger();
		log.info("======");
	}

	@Test
	public void TestInsert() {
		UserDao userdao = session.getMapper(UserDao.class);
		userdao.insertUser(new User(5, "Spring", 100, "BeiJing,dongcheng"));
	}
	@Test
	public void TestupdateUser(){
		UserDao userdao = session.getMapper(UserDao.class);
		userdao.updateUser(new User(4, "Spring", 300, "BeiJing,dongcheng"));
	}
	@Test
	public void TestdeleteUser(){
		UserDao userdao = session.getMapper(UserDao.class);
		userdao.deleteUser(3);;
	}
	@After
	public void Test() {
		session.commit();
		session.close();
	}
}
